package fussbudget.abstracts;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;

import fussbudget.SQL.FBSQL;

public abstract class AbstractDraggableElement extends DefaultMutableTreeTableNode implements Transferable{
	protected int						id				= -1;
	protected AbstractDraggableElement	parentElement	= null;
	protected boolean					isGroup			= false;
	protected String					name			= "";

	public AbstractDraggableElement() {
		super();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public synchronized String getName() {
		return name;
	}

	public synchronized void setName(String name) {
		this.name = name;
		FBSQL.alterString("paymentEntity", "name", name, id);
	}
	
	public AbstractDraggableElement getParentElement() {
		return parentElement;
	}

	public void setParentElement(AbstractDraggableElement parentElement) {
		this.parentElement = parentElement;
	}

	@Override
	public Object getTransferData(DataFlavor arg0) throws UnsupportedFlavorException, IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public DataFlavor[] getTransferDataFlavors() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isDataFlavorSupported(DataFlavor arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result + (isGroup ? 1231 : 1237);
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((parentElement == null) ? 0 : parentElement.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbstractDraggableElement other = (AbstractDraggableElement) obj;
		if (id != other.id)
			return false;
		if (isGroup != other.isGroup)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (parentElement == null) {
			if (other.parentElement != null)
				return false;
		} else if (!parentElement.equals(other.parentElement))
			return false;
		return true;
	}
}
